package 观察者模式;

import java.util.ArrayList;
import java.util.List;

/**
 * 观察者观察的目标对象
 */
public abstract class Subject {

     private List<Observer> observerList=new ArrayList<>();

    public void addObserver(Observer observer){
        observerList.add(observer);
    }
    public void removeObserver(Observer observer){
        observerList.remove(observer);
    }
    public void notifyAllObservers(Object obj){
        for (Observer observer : observerList) {
            observer.update(obj);
        }
    }
}
